X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/2af83e98005a14c439b360a5b9ac636f594d9f0c..38c7d3f9eb7d63937c6654ff5dd6046ce02dd59c:/Super%20Polarity/Actors/MainShip.cs diff --git a/Super Polarity/Actors/MainShip.cs b/Super Polarity/Actors/MainShip.cs index 851c658..1f4f22a 100644 --- a/Super Polarity/Actors/MainShip.cs +++ b/Super Polarity/Actors/MainShip.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; @@ -10,36 +11,40 @@ namespace SuperPolarity { class MainShip : Ship { - - uint Multiplier; - uint Lives; - uint Score; + + public static Color BlueColor; + public static Color RedColor; + ParticleEngine particleEngine; + protected bool Shooting; + protected int ShotCooldown; + public MainShip(Game newGame) : base(newGame) {} + ~MainShip() + { + particleEngine = null; + } + public override void Initialize(Texture2D texture, Vector2 position) { base.Initialize(texture, position); + MainShip.BlueColor = new Color(230, 244, 249); + MainShip.RedColor = new Color(255, 234, 241); + InitParticleEngine(); SetPolarity(Polarity.Positive); - Multiplier = 1; - Lives = 3; - Score = 0; + ShotCooldown = 50; BindInput(); } void InitParticleEngine() { - List texturesList = new List(); - texturesList.Add(game.Content.Load("Graphics\\circle")); - texturesList.Add(game.Content.Load("Graphics\\diamond")); - texturesList.Add(game.Content.Load("Graphics\\star")); - - particleEngine = new ParticleEngine(texturesList, Position); + particleEngine = ParticleEffectFactory.CreatePolarCircle(Position); } void BindInput() @@ -47,6 +52,20 @@ namespace SuperPolarity InputController.Bind("moveX", HandleHorizontalMovement); InputController.Bind("moveY", HandleVerticalMovement); InputController.Bind("changePolarity", HandleChangePolarity); + InputController.Bind("shoot", HandleShot); + } + + protected void HandleShot(float value) + { + Children.Add(ActorFactory.CreateBullet(Position, Angle)); + Shooting = true; + Timer t = new Timer(new TimerCallback(UnlockShot)); + t.Change(ShotCooldown, Timeout.Infinite); + } + + protected void UnlockShot(object state) + { + InputController.Unlock("shoot"); } protected void HandleChangePolarity(float value) @@ -90,11 +109,11 @@ namespace SuperPolarity { if (polarity == Polarity.Positive) { - particleEngine.Color = Color.Red; + particleEngine.Color = MainShip.RedColor; } else if (polarity == Polarity.Negative) { - particleEngine.Color = Color.Blue; + particleEngine.Color = MainShip.BlueColor; } else { @@ -108,6 +127,35 @@ namespace SuperPolarity particleEngine.EmitterLocation = Position; particleEngine.Update(); ConstrainToEdges(); + Shooting = false; + } + + public override void Move(GameTime gameTime) + { + base.Move(gameTime); + + if (Shooting) + { + if (Velocity.X > ActVelocity) + { + Velocity.X = ActVelocity; + } + + if (Velocity.X < -ActVelocity) + { + Velocity.X = -ActVelocity; + } + + if (Velocity.Y > ActVelocity) + { + Velocity.Y = ActVelocity; + } + + if (Velocity.Y < -ActVelocity) + { + Velocity.Y = -ActVelocity; + } + } } public override void Magnetize(Ship ship, float distance, float angle)